<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //假设一个中文占两个字节
    var str = '22两是';

    alert(getStrlen(str))

    function getStrlen(str) {
      var json = { len: 0 };
      var re = /[\u4e00-\u9fa5]/;//此处是Unicode编码在这范围里全是中文
      for (var i = 0; i < str.length; i++) {
        if (re.test(str.charAt(i))) {
          json['len']++;
        }
      };
      return json['len'] + str.length;
    }
  </script>
</body>

</html>